package com.dqhl.community.activity;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseActivity;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.Dlog;
import com.dqhl.community.util.FormatUtils;
import com.dqhl.community.util.JsonUtils;
import com.dqhl.community.view.LuocangDialog;
import com.dqhl.community.view.PictureHandlePopupWindow;
import com.dqhl.community.view.PictureSelectPopupWindow;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by guanluocang on 2016/8/29.
 * 我要投诉Activity
 */
public class ComplainActivity extends BaseActivity implements View.OnClickListener, OnDateSetListener {

    private TextView tv_topTitle;
    private ImageView iv_topBack, iv_add, iv_add_one, iv_add_two, iv_add_three, iv_add_four;//添加图片
    //  添加图片
    private static int REQUESTCODE_PICTURE = 100;
    private static int REQUESTCODE_CAMERA = 101;
    //    private boolean isNullPicOne = true;//imageview处图片是否为空
    private PictureSelectPopupWindow pictureSelectPopupWindow;
    private PictureHandlePopupWindow pictureHandlePopupWindow;
    private String namePicOne = "", namePicTwo = "", namePicThree = "", namePicFour = "";
    private LinearLayout ll_pic_manager;
    private int countPic = 0;// 添加图片数量  imageview处图片是否为空
    private int TAG = 0;//  标记是那张图片
    private Button btn_complainSubmit;// 提交按钮
    private LuocangDialog dialog;//确认Dialog
    private Context context;
    private ImageView iv_moreTime;//期望时间
    //时间选择器
    TimePickerDialog mDialogMonthDayHourMinute;
    TimePickerDialog mDialogAll;
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private TextView tv_showTime;
    private TextView tvHasNum; //剩余可输入多少字
    private EditText etContent;
    private int maxNum = 150; //输入限制的最大字数
    private EditText etName; //业主姓名
    private EditText etTelephoe; //手机号

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_complain);
        context = this;
        // 实例化对象
        initView();
        // 实例化数据
        initData();
        TimePicker();
    }

    // 实例化数据
    private void initData() {
        tv_topTitle.setText(R.string.complain);
        iv_topBack.setVisibility(View.VISIBLE);
        iv_topBack.setOnClickListener(this);
        iv_add.setOnClickListener(this);
        iv_add_one.setOnClickListener(this);
        iv_add_two.setOnClickListener(this);
        iv_add_three.setOnClickListener(this);
        iv_add_four.setOnClickListener(this);
        btn_complainSubmit.setOnClickListener(this);
//        iv_moreTime.setOnClickListener(this);
        pictureSelectPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                pictureSelectPopupWindow.backgroundAlpha(1.0f);
            }
        });
        pictureHandlePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                pictureHandlePopupWindow.backgroundAlpha(1.0f);
            }
        });
    }

    // 实例化对象
    private void initView() {
        tv_topTitle = (TextView) findViewById(R.id.tv_top_title);
        iv_topBack = (ImageView) findViewById(R.id.iv_top_back);
        iv_add = (ImageView) findViewById(R.id.iv_add);
        iv_add_one = (ImageView) findViewById(R.id.iv_add_one);
        iv_add_two = (ImageView) findViewById(R.id.iv_add_two);
        iv_add_three = (ImageView) findViewById(R.id.iv_add_three);
        iv_add_four = (ImageView) findViewById(R.id.iv_add_four);
        btn_complainSubmit = (Button) findViewById(R.id.btn_complainSubmit);
//        iv_moreTime = (ImageView) findViewById(R.id.iv_moreTime);
//        tv_showTime = (TextView) findViewById(R.id.tv_showTime);
        etName = (EditText) findViewById(R.id.et_name);
        etTelephoe = (EditText) findViewById(R.id.et_telephone);
        etContent = (EditText) findViewById(R.id.et_content);
        tvHasNum = (TextView) findViewById(R.id.tv_hasnum);
        tvHasNum.setText("0/" + maxNum);
        etContent.addTextChangedListener(new TextWatcher() {
            CharSequence temp;
            int selectionStart;
            int selectionEnd;

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                temp = charSequence;
            }

            @Override
            public void afterTextChanged(Editable editable) {
                tvHasNum.setText(editable.length() + "/" + maxNum);
                selectionStart = etContent.getSelectionStart();
                selectionEnd = etContent.getSelectionEnd();
                if (temp.length() > maxNum) {
                    toast("不能超过" + maxNum + "个字");
                    editable.delete(selectionStart - 1, selectionEnd);
                    int tempSelection = selectionEnd;
                    etContent.setText(editable);
                    etContent.setSelection(tempSelection); //设置光标在最后
                }
            }
        });

        pictureSelectPopupWindow = new PictureSelectPopupWindow(this, pictureSelectItemsOnClick);
        pictureHandlePopupWindow = new PictureHandlePopupWindow(this, pictureHandleItemsOnClick);
    }

    View.OnClickListener pictureSelectItemsOnClick = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btn_take_photo:   // 调用系统相机
                    Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(camera, REQUESTCODE_CAMERA);
                    pictureSelectPopupWindow.dismiss();
                    break;
                case R.id.btn_pick_photo:   // 调取手机相册
                    Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    startActivityForResult(picture, REQUESTCODE_PICTURE);
                    pictureSelectPopupWindow.dismiss();
                    break;
                case R.id.btn_cancel:   // 取消
                    pictureSelectPopupWindow.dismiss();
                    break;
            }
        }
    };


    View.OnClickListener pictureHandleItemsOnClick = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btn_big_picture:
                    pictureHandlePopupWindow.dismiss();
                    Bundle bundle = new Bundle();
                    if (TAG == 1) {
                        bundle.putString("img_path", namePicOne);
                        overlay(ImageShowerActivity.class, bundle);
                    } else if (TAG == 2) {
                        bundle.putString("img_path", namePicTwo);
                        overlay(ImageShowerActivity.class, bundle);
                    } else if (TAG == 3) {
                        bundle.putString("img_path", namePicThree);
                        overlay(ImageShowerActivity.class, bundle);
                    } else if (TAG == 4) {
                        bundle.putString("img_path", namePicFour);
                        overlay(ImageShowerActivity.class, bundle);
                    }

                    break;
                case R.id.btn_delete: // 删除图片
                    pictureHandlePopupWindow.dismiss();
                    deleteImage();
                    break;
                case R.id.btn_cancel:
                    pictureHandlePopupWindow.dismiss();
                    break;
            }
        }
    };

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_top_back:
                finish();
                break;
            case R.id.iv_add:
                if (countPic == 0) {
                    pictureSelectPopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                    pictureSelectPopupWindow.backgroundAlpha(0.5f);
                } else if (countPic == 1) {
                    pictureSelectPopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                    pictureSelectPopupWindow.backgroundAlpha(0.5f);
                } else if (countPic == 2) {
                    pictureSelectPopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                    pictureSelectPopupWindow.backgroundAlpha(0.5f);
                } else if (countPic == 3) {
                    pictureSelectPopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                    pictureSelectPopupWindow.backgroundAlpha(0.5f);
                }
                break;
            case R.id.iv_add_one:
                TAG = 1;
                pictureHandlePopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                pictureHandlePopupWindow.backgroundAlpha(0.5f);

                break;
            case R.id.iv_add_two:
                TAG = 2;
                pictureHandlePopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                pictureHandlePopupWindow.backgroundAlpha(0.5f);
                break;
            case R.id.iv_add_three:
                TAG = 3;
                pictureHandlePopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                pictureHandlePopupWindow.backgroundAlpha(0.5f);
                break;
            case R.id.iv_add_four:
                TAG = 4;
                pictureHandlePopupWindow.showAtLocation(findViewById(R.id.activity_manager), Gravity.BOTTOM, 0, 0);
                pictureHandlePopupWindow.backgroundAlpha(0.5f);
                break;
            case R.id.btn_complainSubmit: //提交
                doSubmit();
//                getRecord();
                break;
//            case R.id.iv_moreTime:
//                mDialogMonthDayHourMinute.show(getSupportFragmentManager(), "month_day_hour_minute");
//                break;
        }
    }

    /**
     * 提交投诉
     */
    private void doSubmit() {
        String name = etName.getText().toString();
        String telephone = etTelephoe.getText().toString();
        String content = etContent.getText().toString();
        if ("".equals(name) || name.length() <= 0) {
            toast("姓名不能为空");
        } else if ("".equals(telephone) || telephone.length() <= 0) {
            toast("手机号不能为空");
        } else if (!FormatUtils.isMobileNO(telephone)) {
            toast(R.string.toast_telephone_format_error);
        } else if ("".equals(content) || content.length() <= 0) {
            toast("投诉内容不能为空");
        } else {
            File pic_a = new File(namePicOne);
            File pic_b = new File(namePicTwo);
            File pic_c = new File(namePicThree);
            File pic_d = new File(namePicFour);
            RequestParams params = new RequestParams(Config.Api.complain);
            params.addBodyParameter("telephone", telephone);
            params.addBodyParameter("name", name);
            params.addBodyParameter("userid", app.getUserId());
            params.addBodyParameter("content", content);
            if (pic_a.isFile()) {
                Dlog.e(pic_a.getPath());
                params.addBodyParameter("pic_a", pic_a);
            }
            if (pic_b.isFile()) {
                Dlog.e(pic_b.getPath());
                params.addBodyParameter("pic_b", pic_b);
            }
            if (pic_c.isFile()) {
                Dlog.e(pic_c.getPath());
                params.addBodyParameter("pic_c", pic_c);
            }
            if (pic_d.isFile()) {
                Dlog.e(pic_d.getPath());
                params.addBodyParameter("pic_d", pic_d);
            }
            x.http().post(params, new Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    Dlog.e(result);
                    int errCode = JsonUtils.getErrCode(result);
                    if (errCode == 0) {
                        dialog = new LuocangDialog(ComplainActivity.this, "提交成功！", "我们会尽快处理", "确认");
                        dialog.setButtonClickListener(new LuocangDialog.ButtonClickListener() {
                            @Override
                            public void doConfirm() {
                                dialog.dismiss();
                                finish();
                            }
                        });
                        dialog.show();
                    } else {
                        hideCustomLoadBar();
                        toast("提交异常");
                    }
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {
                    toast("提交异常");
                }

                @Override
                public void onCancelled(CancelledException cex) {

                }

                @Override
                public void onFinished() {
                    hideCustomLoadBar();
                }
            });
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            if (requestCode == REQUESTCODE_PICTURE && resultCode == RESULT_OK) {
//                Uri selectedImage = data.getData();
                Uri selectedImage = geturi(data);
                String[] filePathColumns = {MediaStore.Images.Media.DATA};
                Cursor c = this.getContentResolver().query(selectedImage, filePathColumns, null, null, null);
                if (c != null) {
                    c.moveToFirst();
                    int columnIndex = c.getColumnIndex(filePathColumns[0]);
                    String picturePath = c.getString(columnIndex);
                    c.close();
                    //添加图片
                    addImages(picturePath);
                }

            }
            if (requestCode == REQUESTCODE_CAMERA && resultCode == RESULT_OK) {
                String sdState = Environment.getExternalStorageState();
                if (!sdState.equals(Environment.MEDIA_MOUNTED)) {
                    Dlog.e("sd card unmount");
                }
                String name = UUID.randomUUID().toString() + ".jpg";
                File file = new File("/sdcard/pintu");
                file.mkdirs();
                Bundle bundle = data.getExtras();
                //获取相机返回的数据，并转换为图片格式
                Bitmap bitmap = (Bitmap) bundle.get("data");
                FileOutputStream fout = null;
                String fileName = file.getPath() + name;
                try {
                    fout = new FileOutputStream(fileName);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fout);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        fout.flush();
                        fout.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (countPic == 0) {
                    if ("".equals(namePicOne) && namePicOne.length() == 0) {
                        namePicOne = fileName;
                        iv_add_one.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_one, namePicOne);
                        countPic += 1;
                    }
                } else if (countPic == 1) {
                    if ("".equals(namePicOne) && namePicOne.length() == 0) {
                        namePicOne = fileName;
                        iv_add_one.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_one, namePicOne);
                        countPic += 1;
                    } else if ("".equals(namePicTwo) && namePicTwo.length() == 0) {
                        namePicTwo = fileName;
                        iv_add_two.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_two, namePicTwo);
                        countPic += 1;
                    } else if ("".equals(namePicThree) && namePicThree.length() == 0) {
                        namePicThree = fileName;
                        iv_add_three.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_three, namePicThree);
                        iv_add.setVisibility(View.GONE);
                        countPic += 1;
                    } else if ("".equals(namePicFour) && namePicFour.length() == 0) {
                        namePicFour = fileName;
                        iv_add_four.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_four, namePicFour);
                        countPic += 1;
                        iv_add.setVisibility(View.GONE);
                    }
                } else if (countPic == 2) {
                    if ("".equals(namePicOne) && namePicOne.length() == 0) {
                        namePicOne = fileName;
                        iv_add_one.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_one, namePicOne);
                        countPic += 1;
                    } else if ("".equals(namePicTwo) && namePicTwo.length() == 0) {
                        namePicTwo = fileName;
                        iv_add_two.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_two, namePicTwo);
                        countPic += 1;
                    } else if ("".equals(namePicThree) && namePicThree.length() == 0) {
                        namePicThree = fileName;
                        iv_add_three.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_three, namePicThree);
                        countPic += 1;
                    } else if ("".equals(namePicFour) && namePicFour.length() == 0) {
                        namePicFour = fileName;
                        iv_add_four.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_four, namePicFour);
                        iv_add.setVisibility(View.GONE);
                        countPic += 1;
                    }
                } else if (countPic == 3) {
                    if ("".equals(namePicOne) && namePicOne.length() == 0) {
                        namePicOne = fileName;
                        iv_add_one.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_one, namePicOne);
                        iv_add.setVisibility(View.GONE);
                        countPic += 1;
                    } else if ("".equals(namePicTwo) && namePicTwo.length() == 0) {
                        namePicTwo = fileName;
                        iv_add_two.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_two, namePicTwo);
                        iv_add.setVisibility(View.GONE);
                        countPic += 1;
                    } else if ("".equals(namePicThree) && namePicThree.length() == 0) {
                        namePicThree = fileName;
                        iv_add_three.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_three, namePicThree);
                        iv_add.setVisibility(View.GONE);
                        countPic += 1;
                    } else if ("".equals(namePicFour) && namePicFour.length() == 0) {
                        namePicFour = fileName;
                        iv_add_four.setVisibility(View.VISIBLE);
                        x.image().bind(iv_add_four, namePicFour);
                        countPic += 1;
                        iv_add.setVisibility(View.GONE);
                    }
                }
            }

        }
    }

    /**
     * 解决小米部分手机调用系统相册失败
     *
     * @param intent
     * @return
     */
    public Uri geturi(android.content.Intent intent) {
        Uri uri = intent.getData();
        String type = intent.getType();
        if (uri.getScheme().equals("file") && (type.contains("image/"))) {
            String path = uri.getEncodedPath();
            if (path != null) {
                path = Uri.decode(path);
                ContentResolver cr = this.getContentResolver();
                StringBuffer buff = new StringBuffer();
                buff.append("(").append(MediaStore.Images.ImageColumns.DATA).append("=")
                        .append("'" + path + "'").append(")");
                Cursor cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        new String[]{MediaStore.Images.ImageColumns._ID},
                        buff.toString(), null, null);
                int index = 0;
                for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
                    index = cur.getColumnIndex(MediaStore.Images.ImageColumns._ID);
                    // set _id value
                    index = cur.getInt(index);
                }
                if (index == 0) {
                    // do nothing
                } else {
                    Uri uri_temp = Uri
                            .parse("content://media/external/images/media/"
                                    + index);
                    if (uri_temp != null) {
                        uri = uri_temp;
                    }
                }
            }
        }
        return uri;
    }

    //添加图片
    public void addImages(String path) {
        if (countPic == 0) {
            if ("".equals(namePicOne) && namePicOne.length() == 0) {
                namePicOne = path;
                iv_add_one.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_one, namePicOne);
                countPic += 1;
            }
        } else if (countPic == 1) {
            if ("".equals(namePicOne) && namePicOne.length() == 0) {
                namePicOne = path;
                iv_add_one.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_one, namePicOne);
                countPic += 1;
            } else if ("".equals(namePicTwo) && namePicTwo.length() == 0) {
                namePicTwo = path;
                iv_add_two.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_two, namePicTwo);
                countPic += 1;
            } else if ("".equals(namePicThree) && namePicThree.length() == 0) {
                namePicThree = path;
                iv_add_three.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_three, namePicThree);
                iv_add.setVisibility(View.GONE);
                countPic += 1;
            } else if ("".equals(namePicFour) && namePicFour.length() == 0) {
                namePicFour = path;
                iv_add_four.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_four, namePicFour);
                countPic += 1;
                iv_add.setVisibility(View.GONE);
            }
        } else if (countPic == 2) {
            if ("".equals(namePicOne) && namePicOne.length() == 0) {
                namePicOne = path;
                iv_add_one.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_one, namePicOne);
                countPic += 1;
            } else if ("".equals(namePicTwo) && namePicTwo.length() == 0) {
                namePicTwo = path;
                iv_add_two.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_two, namePicTwo);
                countPic += 1;
            } else if ("".equals(namePicThree) && namePicThree.length() == 0) {
                namePicThree = path;
                iv_add_three.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_three, namePicThree);
                countPic += 1;
            } else if ("".equals(namePicFour) && namePicFour.length() == 0) {
                namePicFour = path;
                iv_add_four.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_four, namePicFour);
                iv_add.setVisibility(View.GONE);
                countPic += 1;
            }
        } else if (countPic == 3) {
            if ("".equals(namePicOne) && namePicOne.length() == 0) {
                namePicOne = path;
                iv_add_one.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_one, namePicOne);
                iv_add.setVisibility(View.GONE);
                countPic += 1;
            } else if ("".equals(namePicTwo) && namePicTwo.length() == 0) {
                namePicTwo = path;
                iv_add_two.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_two, namePicTwo);
                iv_add.setVisibility(View.GONE);
                countPic += 1;
            } else if ("".equals(namePicThree) && namePicThree.length() == 0) {
                namePicThree = path;
                iv_add_three.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_three, namePicThree);
                iv_add.setVisibility(View.GONE);
                countPic += 1;
            } else if ("".equals(namePicFour) && namePicFour.length() == 0) {
                namePicFour = path;
                iv_add_four.setVisibility(View.VISIBLE);
                x.image().bind(iv_add_four, namePicFour);
                countPic += 1;
                iv_add.setVisibility(View.GONE);
            }
        }
    }

    //删除图片
    public void deleteImage() {
        if (TAG == 1) {
            namePicOne = "";
            iv_add_one.setVisibility(View.GONE);
            iv_add.setVisibility(View.VISIBLE);
            iv_add.setImageResource(R.drawable.addimage);
            countPic -= 1;
        } else if (TAG == 2) {
            namePicTwo = "";
            iv_add_two.setVisibility(View.GONE);
            iv_add.setVisibility(View.VISIBLE);
            iv_add.setImageResource(R.drawable.addimage);
            countPic -= 1;
        } else if (TAG == 3) {
            namePicThree = "";
            iv_add_three.setVisibility(View.GONE);
            iv_add.setVisibility(View.VISIBLE);
            iv_add.setImageResource(R.drawable.addimage);
            countPic -= 1;
        } else if (TAG == 4) {
            namePicFour = "";
            iv_add_four.setVisibility(View.GONE);
            iv_add.setVisibility(View.VISIBLE);
            iv_add.setImageResource(R.drawable.addimage);
            countPic -= 1;
        }
    }

    @Override
    public void onDateSet(com.jzxiang.pickerview.TimePickerDialog timePickerView, long millseconds) {
        String text = getDateToString(millseconds);
        tv_showTime.setVisibility(View.VISIBLE);
        tv_showTime.setText(text);
    }

    public String getDateToString(long time) {
        Date d = new Date(time);
        return sf.format(d);
    }

    //时间选择器
    public void TimePicker() {
        long tenYears = 10L * 365 * 1000 * 60 * 60 * 24L;
        mDialogAll = new com.jzxiang.pickerview.TimePickerDialog.Builder()
                .setCallBack(this)
                .setCancelStringId("Cancel")
                .setSureStringId("Sure")
                .setTitleStringId("TimePicker")
                .setYearText("Year")
                .setMonthText("Month")
                .setDayText("Day")
                .setHourText("Hour")
                .setMinuteText("Minute")
                .setCyclic(false)
                .setMinMillseconds(System.currentTimeMillis())
                .setMaxMillseconds(System.currentTimeMillis() + tenYears)
                .setCurrentMillseconds(System.currentTimeMillis())
                .setThemeColor(getResources().getColor(R.color.timepicker_dialog_bg))
                .setType(Type.ALL)
                .setWheelItemTextNormalColor(getResources().getColor(R.color.timetimepicker_default_text_color))
                .setWheelItemTextSelectorColor(getResources().getColor(R.color.timepicker_toolbar_bg))
                .setWheelItemTextSize(12)
                .build();


        mDialogMonthDayHourMinute = new TimePickerDialog.Builder()
                .setType(Type.MONTH_DAY_HOUR_MIN)
                .setCallBack(this)
                .build();
    }
}
